/*
 * @Author: your name
 * @Date: 2021-01-06 11:38:26
 * @LastEditTime: 2021-10-01 00:16:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \express-seed\routes\updataImg.JS
 */
const express = require("express");
const router = express.Router();
const Result = require("../../models/result");
const phantom = require("phantom");

const path = require("path");
// console.log("phantom :>> ", phantom);
const { selectImgService } = require("../../service/imgService");

router.get("/", async(req, res, next) => {
    const ress = await selectImgService();
    new Result(ress, "查询成功").success(res);
});

router.get("/create_img", async(req, res, next) => {
    phantom.create().then(function(ph) {
        ph.createPage().then(function(page) {
            page.open("https://cn.vuejs.org/").then(function(status) {
                page.property("viewportSize", { width: 1920, height: 1080 });
                page.render("./public/img/1.png").then(function() {
                    console.log("Page rendered");
                    ph.exit();
                });
            });
        });
    });
    new Result({ img: "http://localhost:3000/public/img/1.png" }, "查询成功").success(res);
});

module.exports = router;